package controller

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"log"
	"net/http"
	"week1-project/pkg"
)

//普通上传(图,视频)

func CloudUpload(c *gin.Context) {
	file, _ := c.FormFile("file")
	log.Println(file.Filename)

	dst := "袁征11.16作业展示.mp4" + file.Filename
	// 上传文件至指定的完整文件路径
	c.SaveUploadedFile(file, dst)
	//判断格式是否正确
	if !(file.Filename == ".mp4" || file.Filename == ".mov") {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "视频格式不正确",
			"err":  zap.Error,
		})
		return
	}
	//视频内存大小不能超过20G
	if file.Size > 1024*1024*20 {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "视频内存过大",
			"err":  zap.Error,
		})
		return
	}
	pkg.OssCloudStorage(dst, file.Filename)
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "上传成功",
	})
}

//网络流上传(图片水印)

func Upload(c *gin.Context) {
	file, _ := c.FormFile("file")
	log.Println(file.Filename)

	dst := "./img" + file.Filename
	// 上传文件至指定的完整文件路径
	c.SaveUploadedFile(file, dst)
	pkg.Upload(file.Filename)
	if file.Size > 1024*10 {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "视频封面过大",
			"err":  zap.Error,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "上传成功",
	})
}
